<!DOCTYPE html
    PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>
    <title>产品列表</title>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8" />
    <script src="../../scripts/boot.js" type="text/javascript"></script>


</head>

<body>
    <style type="text/css">
        html,
        body {
            margin: 0;
            padding: 0;
            border: 0;
            width: 100%;
            height: 100%;
            overflow: hidden;
        }
    </style>
    <div class="mini-toolbar" style="padding:2px;border-bottom:0;">
        <table style="width:100%;">
            <tr>
                <td style="width:100%;">
                    <a class="mini-button" iconCls="icon-add" onclick="add()">新增</a>
                </td>

            </tr>
        </table>
    </div>
    <!--撑满页面-->
    <div class="mini-fit">

        <div id="quoteinfo" class="mini-datagrid" style="width:100%;height:100%;" url="../../quoteinfoaction"
            ajaxType="get" multiSelect="true" idField="id" allowResize="false" showPager="false" pageSize="10">
            <div property="columns">
                <div type="indexcolumn">序号</div>
                <div field="supplierId" width="120" headerAlign="center" allowSort="true">供应商编号</div>
                <div field="supplierName" width="120" headerAlign="center" allowSort="true">供应商名称</div>
                <div field="productName" width="120" headerAlign="center" allowSort="true">报价产品</div>
                <div field="phone" width="100" headerAlign="center">联系电话</div>
                <div field="email" width="100" headerAlign="center" allowSort="true">电子邮箱</div>
                <div field="quote" width="100" headerAlign="center" allowSort="true" dataType="currency"
                    renderer="onQuoteValid">
                    当前报价</div>
                <div field="createTime" width="100" headerAlign="center" dateFormat="yyyy-MM-dd" allowSort="true">报价时间
                </div>

                <!-- 操作 -->
                <div name="action" width="120" headerAlign="center" renderer="onActionRenderer" cellStyle="padding:0;">
                    操作</div>
            </div>
        </div>

    </div>
    <div id="pager1" class="mini-pager" style="width:100%;background:#f0f3f7;border:solid 1px #ccc;"
        onpagechanged="onPageChanged" sizeList="[5,10,20,50]" showPageSize="true" showPageIndex="true"
        showPageInfo="true" buttons="#buttons">

    </div>

    <div id="buttons">
        <a style="margin-left: 300px;">@岗前培训结业模拟试题</a>
    </div>
    <script type="text/javascript">

        mini.parse();
        var grid = mini.get("quoteinfo");
        grid.load();
        grid.sortBy("createTime", "desc");
        /* 自定义分页功能 */
        var pager = mini.get("pager1");
        // 数据加载完毕后加载分页总数
        grid.on("load", function (e) {
            pager.setTotalCount(grid.totalCount);
        });
        function onPageChanged(e) {
            pager.totalCount = grid.totalCount;
            grid.load({
                pageIndex: e.pageIndex,
                pageSize: e.pageSize,
                sortField: e.sortField,
                sortOrder: e.sortOrder
            });

        }
        // 操作按钮
        function onActionRenderer(e) {
            var grid = e.sender;
            var record = e.record;
            var uid = record._id;
            var rowIndex = e.rowIndex;

            var s = ' <a class="mini-button" href="javascript:delRow(\'' + uid + '\')"">删除</a>';

            return s;
        }
        // 当前报价校验
        function onQuoteValid(e) {
            if (e.value > 200) {
                e.cellStyle = "background-color:yellow;"
            }
            return e.value;
        }

        
        // 新增报价信息
        function add() {
            mini.open({
                url: "pages/quoteinfo/quoteinfoadd.html",
                title: "新增报价信息", width: 600, height: 400, allowResize: false,
                ondestroy: function (action) {

                    grid.reload();
                }
            });
        }

        // 删除当前记录
        function delRow(row_uid) {
            var row = grid.getRowByUID(row_uid);
            if (row) {
                mini.confirm("确定删除记录？", "确定？",
                    function (action) {
                        if (action == "ok") {
                            grid.loading("删除中，请稍后......");
                            $.ajax({
                                url: "../../quoteinfoaction",
                                type: "post",
                                data: {
                                    method: "del",
                                    supplierId: row.supplierId,
                                    productId: row.productId
                                },
                                success: function (text) {
                                    var res = mini.decode(text);
                                    mini.alert(res.msg);
                                    grid.reload();
                                },
                                error: function () {
                                }
                            });
                        }
                    }
                );
            }
        }

    </script>

</body>

</html>